import React, { Component } from 'react'
import { connect } from 'react-redux';
import Detlist from "../components/detlist/detOnelist"
 class detlist extends Component {
    constructor(props){
        super(props)
        this.state={
            kind:"2",
            totalEssay:"",
            newEssay:""
        }
    }
  
    componentDidMount(){
        
        // if(this.props.location.state&&this.props.location.state.params){//判断当前有参数
        //     let recvParam=this.props.location.state.params;
        //     console.log(recvParam);
        //     this.setState({
        //         kind:recvParam
        //     })
        //     sessionStorage.setItem('data',recvParam);// 存入到sessionStorage中
        // }else{
        //     let recvParam=sessionStorage.getItem('data');// 当state没有参数时，取sessionStorage中的参数
        //     this.setState({
        //         kind:recvParam
        //     })
        // }

        // console.log(this.props.location.state.kind)
        // console.log(this.props.state.textReducer)
        console.log(this.props.match.params.kind)
        console.log(this.props.state.textReducer.state)
        this.setState({
            totalEssay:this.props.state.textReducer.state
        },()=>{
            console.log(this.state.totalEssay)
        })
    }
    essayList=()=>{
        let newarr = [];
        this.state.totalEssay.forEach((item,index)=>{
            if(item.kind == this.props.match.params.kind){
                newarr.push(item)
            }
            // return 1
        })
        console.log(newarr)
        newarr.map((item,index)=>{
            <Detlist info={item}></Detlist>
        })
            // this.setState({
            //     newEssay:newarr
            // },()=>{
            //     console.log(this.state.newEssay)
            // })
            
    }
    render() {
        return (
            <div>
                <p>{this.state.totalEssay? this.essayList():"null22"}</p>
                <Detlist></Detlist>
                <p>{this.state.kind}</p>
            </div>
        )
    }
}
export default connect((state)=>({state}))(detlist)